/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ThreadsScreen.java
 *
 * Created on Apr 18, 2011, 3:46:07 PM
 */

package forumGUI;

import client.ForumClientListener;
import client.TcpClient;
import forum.Post;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Enumeration;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeSelectionModel;
import messaage.AddedForumMsg;
import messaage.AddedFriendMsg;
import messaage.AddedPostMsg;
import messaage.ConnectedMsg;
import messaage.CreatedThreadMsg;
import messaage.DisconnectedMsg;
import messaage.EditedPostMsg;
import messaage.ErrorMsg;
import messaage.GetFriendsListMsg;
import messaage.GetListOfForumsMsg;
import messaage.GetThreadMsg;
import messaage.GotFriendsListMsg;
import messaage.GotListOfForumsMsg;
import messaage.GotThreadMsg;
import messaage.GotTopicsOfForumMsg;
import messaage.LoggedInMsg;
import messaage.LoggedOffMsg;
import messaage.LogoutMsg;
import messaage.RegisteredMsg;
import messaage.RemovedForumMsg;
import messaage.RemovedFriendMsg;
import messaage.RemovedPostMsg;
import messaage.RemovedThreadMsg;
import messaage.RemovedUserMsg;
import utils.LogHelper;

/**
 *
 * @author Olga
 */
public class ThreadsScreen extends javax.swing.JFrame implements client.MessagesListener {
    private TcpClient client;
    private String username;
    private boolean isModerator;
    private int forumID;
    private String forumSubject;

    private DefaultMutableTreeNode forumRoot;               // root of the tree
    private TreeModel forumTreeModel;                // model of the tree
														// who sended
															// getThread

    /** Creates new form ThreadsScreen */
    public ThreadsScreen(TcpClient _client, String _username,
			boolean _isModerator, int _forumID, String _forumSubject) {
        initComponents();
        this.setBackground();

        this.client = _client;
        this.username = _username;
        this.isModerator = _isModerator;
        this.forumID = _forumID;
        this.forumSubject = _forumSubject;
        this.postContentField.setEditable(false);

        // set root of tree to be a subject of forum
        this.forumRoot = new DefaultMutableTreeNode(this.forumSubject);
        // this.forumTree = new JTree(this.forumRoot);
        this.forumTreeModel = new DefaultTreeModel(forumRoot);
        this.forumTree.setModel(this.forumTreeModel);
        this.forumTree.getSelectionModel().setSelectionMode(
                        TreeSelectionModel.SINGLE_TREE_SELECTION);
    }

    public void setBackground()
    {
        Container con =this.getContentPane();
        JPanel panelBgImg;
        con.setLayout(null);
        final String photoPath = "src/images/screen.jpg";
        ImageIcon imh = new ImageIcon(photoPath);
//        setSize(imh.getIconWidth(), imh.getIconHeight());

        panelBgImg = new JPanel()
        {
            @Override
            public void paintComponent(Graphics g)
            {
                Image img = new ImageIcon(photoPath).getImage();

                Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
                setPreferredSize(size);
                setMinimumSize(size);
                setMaximumSize(size);
                setSize(size);
                setLayout(null);
                g.drawImage(img, 0, 0, null);
            }
        };

        con.add(panelBgImg);
        panelBgImg.setBounds(0, 0, imh.getIconWidth(), imh.getIconHeight());

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        forumTree = new javax.swing.JTree();
        forumConnentLabel = new javax.swing.JLabel();
        postContentLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        postContentField = new javax.swing.JTextArea();
        addTopicButton = new javax.swing.JButton();
        addReplyButton = new javax.swing.JButton();
        editPostButton = new javax.swing.JButton();
        BackToForumsButton = new javax.swing.JButton();
        logoutButton = new javax.swing.JButton();
        removePost = new javax.swing.JButton();
        friendsButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        forumTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        forumTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                forumTreeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(forumTree);

        forumConnentLabel.setText("Forum:");

        postContentLabel.setText("Post content:");

        postContentField.setColumns(20);
        postContentField.setEditable(false);
        postContentField.setRows(5);
        jScrollPane2.setViewportView(postContentField);

        addTopicButton.setText("add topic");
        addTopicButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTopicButtonActionPerformed(evt);
            }
        });

        addReplyButton.setText("add reply");
        addReplyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addReplyButtonActionPerformed(evt);
            }
        });

        editPostButton.setText("edit post");
        editPostButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editPostButtonActionPerformed(evt);
            }
        });

        BackToForumsButton.setText("back to forums");
        BackToForumsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackToForumsButtonActionPerformed(evt);
            }
        });

        logoutButton.setText("logout");
        logoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutButtonActionPerformed(evt);
            }
        });

        removePost.setText("remove post");
        removePost.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removePostActionPerformed(evt);
            }
        });

        friendsButton.setText("friends list");
        friendsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                friendsButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addTopicButton)
                        .addGap(18, 18, 18)
                        .addComponent(editPostButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(addReplyButton)
                        .addGap(18, 18, 18)
                        .addComponent(removePost))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(forumConnentLabel)
                        .addGap(151, 151, 151))
                    .addComponent(jScrollPane1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(friendsButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                                    .addComponent(BackToForumsButton, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(logoutButton)))
                        .addGap(20, 20, 20))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(postContentLabel)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(forumConnentLabel)
                    .addComponent(postContentLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addTopicButton)
                    .addComponent(editPostButton)
                    .addComponent(logoutButton)
                    .addComponent(BackToForumsButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addReplyButton)
                    .addComponent(removePost)
                    .addComponent(friendsButton))
                .addGap(35, 35, 35))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BackToForumsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackToForumsButtonActionPerformed
                    // create new forums screen
		forumsScreen fs = new forumsScreen(this.client, this.username, this.isModerator);
            // sets new frame as listener
		ForumClientListener tempListener = (ForumClientListener) this.client.getListener();
		tempListener.getConnector().addListener(fs);
            // create getList of forums msg
		GetListOfForumsMsg listMsg = new GetListOfForumsMsg(this.username);
		this.client.sendMessage(listMsg);
            // remove this frame from socket liseners
		tempListener.getConnector().removeListener(this);
		this.setVisible(false);
    }//GEN-LAST:event_BackToForumsButtonActionPerformed

    private void forumTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_forumTreeValueChanged
 		// Show content in content window
		DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();

                if (node == null)
                     return;

		// if root node selected, clean the content text field
		if (node == this.forumRoot) {
			this.postContentField.setText("");
			return;
		}

                //if post was selected
		forum.Post p = (forum.Post) node.getUserObject();
		String content = "";
		content += p.getAuthor() + " posted at " + p.getDate() + "\n";
		content += "Subject: " + p.getSubject() + "\n";
		content += "Content:\n   " + p.getContent();
		this.postContentField.setText(content);


		// if thread node is selected send getThreadRequest
		// opening the thread note but not post node!!!
		// othrewize do nothing special
		if (node.getLevel() == 1 && node.isLeaf()) {
			node.removeAllChildren();
			this.client.sendMessage(new GetThreadMsg(this.username, this.forumID+"", p.getID()+""));
		}
    }//GEN-LAST:event_forumTreeValueChanged

    private void addTopicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTopicButtonActionPerformed
        	addThreadScreen ats = new addThreadScreen(client, username, this,
				this.forumID);
		ats.setVisible(true);
		this.setEnabled(false);
    }//GEN-LAST:event_addTopicButtonActionPerformed

    private void addReplyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addReplyButtonActionPerformed
            //get selected node
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.forumTree.getLastSelectedPathComponent();
                 if (node == null)
                     return;
		// if root node is selected, pick error msg
		if (node == this.forumRoot) {
			JOptionPane.showMessageDialog(this, "You can reply only to posts");
			return;
		}

		Post toReply = (Post) node.getUserObject();
                System.out.println("please add reply to post "+ toReply.getID()+" "+toReply.getSubject());
		addPostScreen aps = new addPostScreen(this.client, this.username, this,
				toReply.getID(), this.forumID);
		aps.setVisible(true);
		this.setEnabled(false);
    }//GEN-LAST:event_addReplyButtonActionPerformed

    private void editPostButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPostButtonActionPerformed
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) this.forumTree
                        .getLastSelectedPathComponent();

        if (node == null)
             return;

        // if root node or thread node is selected, pick error msg
        if (node == this.forumRoot || node.getLevel() == 1) {
                JOptionPane.showMessageDialog(this,
                                "You can edit only posts, wich are not roots or forums");
                return;
        }

        Post toEdit = (Post) node.getUserObject();
        editPostScreen eps = new editPostScreen(this.client, this.username,
                        this, toEdit, this.forumID);
        eps.setVisible(true);
        this.setEnabled(false);
    }//GEN-LAST:event_editPostButtonActionPerformed

    private void removePostActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePostActionPerformed
	System.err.println("removePostButton not supposted yet");
    }//GEN-LAST:event_removePostActionPerformed

    private void friendsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_friendsButtonActionPerformed
        // create new friendsScreen
        friendsScreen fs = new friendsScreen(this.client, this.username,
                        this.isModerator);
        // adds new listener to socket
        ((ForumClientListener) this.client.getListener()).getConnector()
                        .addListener(fs);
        // send getFriens msg
        this.client.sendMessage(new GetFriendsListMsg(this.username));
        ForumClientListener tempListener = (ForumClientListener) this.client
                        .getListener();
        tempListener.getConnector().removeListener(this);
        this.setVisible(false);
    }//GEN-LAST:event_friendsButtonActionPerformed

    private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed
        LogoutMsg msg = new LogoutMsg(username);
	this.client.sendMessage(msg);
    }//GEN-LAST:event_logoutButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                //new ThreadsScreen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BackToForumsButton;
    private javax.swing.JButton addReplyButton;
    private javax.swing.JButton addTopicButton;
    private javax.swing.JButton editPostButton;
    private javax.swing.JLabel forumConnentLabel;
    private javax.swing.JTree forumTree;
    private javax.swing.JButton friendsButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton logoutButton;
    private javax.swing.JTextArea postContentField;
    private javax.swing.JLabel postContentLabel;
    private javax.swing.JButton removePost;
    // End of variables declaration//GEN-END:variables

   @Override
	public void connected(ConnectedMsg msg) {
	}

	@Override
	public void disconnected(DisconnectedMsg msg) {
		// TODO Auto-generated method stub
	}

	@Override
	public void errorMessage(ErrorMsg msg) {
		String body = msg.getBody();
		JOptionPane.showMessageDialog(this, body);
	}

	@Override
	public void registered(RegisteredMsg msg) {
	}

	@Override
	public void loggedIn(LoggedInMsg msg) {
	}

	@Override
	public void loggedOff(LoggedOffMsg msg) {
		this.setVisible(false);
		MainScreen ms = new MainScreen(client);
		ms.setVisible(true);
	}

	@Override
	public void gotListOfForums(GotListOfForumsMsg msg) {
	}

	@Override
	public void gotTopicsOfForum(GotTopicsOfForumMsg msg) {
		if (msg.getForumID() == this.forumID) {
			for (forum.Thread t : msg.getListOfTopics()) {
				DefaultMutableTreeNode node = new DefaultMutableTreeNode(t.getRoot());
				this.forumRoot.add(node);
			}
                        // repaint
                        this.forumTreeModel = new DefaultTreeModel(this.forumRoot);
			this.forumTree.setModel(this.forumTreeModel);
		}
		this.setVisible(true);
	}

	/**
	 * ASSUMPTION!!! User does not selected any other thread until he has got
	 * the reply gotThread from server
	 *
	 * @param msg
	 */
	@Override
	public void gotThread(GotThreadMsg msg) {
            if (msg.getForumID() != this.forumID || this.forumRoot.isLeaf())
                return;
            
            // search for thread node to fill it
            DefaultMutableTreeNode node = null;
            for (Enumeration e = this.forumRoot.children(); e.hasMoreElements();){
                 node = (DefaultMutableTreeNode)e.nextElement();
                 Post post = (Post) node.getUserObject();
                 if (post.getID() == msg.getThread().getID())
                     break;
            }
            // if node found and it still has no children
            if (node != null && node.isLeaf() ){
                this.fillThread(node, msg.getThread().getRoot());
                // repaint
               /* this.forumTreeModel = new DefaultTreeModel(this.forumRoot);
                * this.forumTree.setModel(this.forumTreeModel);
                *
                */
            }
	}

        private void fillThread(DefaultMutableTreeNode node, Post post) {
            if (post.getReplies() != null && post.getReplies().size() > 0) {
                    for (Post p : post.getReplies()) {
                            DefaultMutableTreeNode n = new DefaultMutableTreeNode(p);
                            node.add(n);
                            fillThread(n, p);
                    }
            }
	} // fillThread

	@Override
	public void addedPost(AddedPostMsg msg) {
		int forumIdOfAddedPost = Integer.parseInt(msg.getForumID());
		int parentIDofAddedPost = Integer.parseInt(msg.getParentID());
		if (forumIdOfAddedPost == this.forumID) {
                    // do not add post twice
                    if (this.findNode(Integer.parseInt(msg.getPostID()), this.forumRoot) != null)
                        return;
		    // search for parent in GUI tree
                    DefaultMutableTreeNode parent = this.findNode(parentIDofAddedPost, this.forumRoot);
                    // if parent with parenID was not found
                    if (parent == null){
                        LogHelper.instance().log("Cannot add post to GUI because post with parentID "
								+ parentIDofAddedPost + " was not found");
                        return;
                    }

                    // add reply to parent post
                    Post parentPost = (Post) parent.getUserObject();
                    Post reply = new Post(Integer.parseInt(msg.getPostID()), msg.getSubject(), msg.getContent(), parentPost, msg.getAuthor());
                    parentPost.addReply(reply);

                    // add reply to tree
                    DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(reply);
                    parent.add(toAdd);
                    // repaint
                    this.forumTreeModel = new DefaultTreeModel(this.forumRoot);
                    this.forumTree.setModel(this.forumTreeModel);

                    // notify to friend
                    if (msg.isFriend())
			JOptionPane.showMessageDialog(this, "Your friend added a new post");
		}
	}

	private synchronized DefaultMutableTreeNode findNode(int postIDtoFind,
			DefaultMutableTreeNode node) {
           DefaultMutableTreeNode ans = null;
           DefaultMutableTreeNode tmpNode = null;
           if (node != null && !node.isLeaf()){
               for (Enumeration e = node.children(); e.hasMoreElements();){
                 tmpNode = (DefaultMutableTreeNode)e.nextElement();
                 Post post = (Post) tmpNode.getUserObject();
                 if (post.getID() == postIDtoFind ){
                     ans = tmpNode;
                     return ans;
                 }
                 ans = findNode(postIDtoFind, tmpNode);
                 if (ans != null)
                     return ans;
               }
            }
           return ans;
	}

	@Override
	public void createdThread(CreatedThreadMsg msg) {
		if (msg.getForumID() == this.forumID) {
			DefaultMutableTreeNode n = new DefaultMutableTreeNode(msg
					.getThread().getRoot());
			this.forumRoot.add(n);
			this.forumTreeModel = new DefaultTreeModel(this.forumRoot);
			this.forumTree.setModel(this.forumTreeModel);
                // pick notification to the friend
		if (msg.getIsFriend())
			JOptionPane.showMessageDialog(this,
					"Your friend created a new thread");
		}
	}

	@Override
	public void addedForum(AddedForumMsg msg) {
	}

	@Override
	public void removedForum(RemovedForumMsg msg) {
		if (msg.getForumID() == this.forumID) {
			JOptionPane
					.showMessageDialog(
							this,
							"Sorry, but this forum was just removed.\nYou will be redirected to forums list :(");
			forumsScreen fs = new forumsScreen(this.client, this.username,
					this.isModerator);
			ForumClientListener tempListener = (ForumClientListener) this.client
					.getListener();
			tempListener.getConnector().addListener(fs);
			GetListOfForumsMsg listMsg = new GetListOfForumsMsg(this.username);
			this.client.sendMessage(listMsg);
			tempListener.getConnector().removeListener(this);
			this.setVisible(false);
		}
	}

	@Override
	public void editedPost(EditedPostMsg msg) {
            int forumIDofEditedPost = Integer.parseInt(msg.getForumID());
            int postIDofEditedPost = Integer.parseInt(msg.getPostID());
            System.out.println("arrived to editedPost");
            if (forumIDofEditedPost == this.forumID) {

                DefaultMutableTreeNode postNode = this.findNode(postIDofEditedPost, this.forumRoot);
                // if post with ID postIDofEditedPost was not found
                if (postNode == null){
                    LogHelper.instance().log("Cannot edit post in GUI because post with postID "
                                                            + postIDofEditedPost + " was not found");
                    return;
                }
                // edit reply to forum
                String content = msg.getNewContent();
                 // edit reply in tree
                Post postToEdit = (Post) postNode.getUserObject();
                postToEdit.editPost(content);
                postToEdit.setDate(msg.getDate());

                // if edited post is selected post edit Post content text area
                if (this.forumTree.getLastSelectedPathComponent() == postNode){
                    String contentToSet = "";
                    contentToSet += postToEdit.getAuthor() + " posted at " + postToEdit.getDate() + "\n";
                    contentToSet += "Subject: " + postToEdit.getSubject() + "\n";
                    contentToSet += "Content:\n   " + postToEdit.getContent();
                    this.postContentField.setText(contentToSet);
                }

                // notify to friend
                if (msg.isFriend())
                        JOptionPane.showMessageDialog(this, "Your friend edited a post");
            }
	}

	@Override
	public void removedUser(RemovedUserMsg msg) {
		if (msg.getUsernameToRemove().equalsIgnoreCase(this.username)) {
			JOptionPane.showMessageDialog(this,
					"Sorry, but you was just removed from the forum :(");
	        ForumClientListener tempListener = (ForumClientListener) this.client.getListener();
	        tempListener.getConnector().removeListener(this);
			this.setVisible(false);
		}
	}

	@Override
	public void removedThread(RemovedThreadMsg msg) {
		JOptionPane.showMessageDialog(this,
				"Sorry, removedThread in ThreadsScreen not supporeted yet :(");
	}

	@Override
	public void removedPost(RemovedPostMsg msg) {
		JOptionPane.showMessageDialog(this,
				"Sorry, removedPost in ThreadsScreen not supporeted yet :(");
	}

	@Override
	public void addedFriend(AddedFriendMsg msg) {
	}

	@Override
	public void removedFriend(RemovedFriendMsg msg) {
	}

	@Override
	public void gotFriendsList(GotFriendsListMsg msg) {
	}

}
